﻿<%@ Page Title="Registrar Prestamo" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Registrar.aspx.cs" Inherits="Triunfadores.Web.Prestamos.Registrar" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <asp:HiddenField ID="hfIdPrestamos" runat="server" />
    <div class="row">
        <div class="col-lg-6">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">Cliente</h3>
                </div>
                <div class="box-body">
                    <div class="form-group">
                        <label class="control-label col-md-1">DNI</label>
                        <div class="col-md-8">
                            <asp:TextBox ID="tbxDniSocio" CssClass="form-control input-sm" MaxLength="8" runat="server" />
                            <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender" TargetControlID="tbxDniSocio"
                                FilterType="Numbers" runat="server"></ajaxToolkit:FilteredTextBoxExtender>
                        </div>
                        <asp:Button ID="btnBuscarSocio" CssClass="btn btn-default btn-sm" Text="Buscar" runat="server" OnClick="btnBuscarSocio_Click" />
                    </div>
                    <asp:UpdatePanel ID="upSocios" runat="server">
                        <ContentTemplate>
                            <div class="form-group">
                                <div class="col-md-8">
                                    <strong>
                                        <asp:Label ID="lblDatosSocio" Text="" runat="server" /></strong>
                                </div>
                            </div>
                        </ContentTemplate>
                        <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="btnBuscarSocio" EventName="Click" />
                        </Triggers>
                    </asp:UpdatePanel>
                </div>
            </div>
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">Avalador</h3>
                </div>
                <div class="box-body">
                    <div class="form-group">
                        <label class="control-label col-md-1">DNI</label>
                        <div class="col-md-8">
                            <asp:TextBox ID="tbxDniAvaldo" CssClass="form-control input-sm" runat="server" MaxLength="8" />
                            <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" TargetControlID="tbxDniAvaldo"
                                FilterType="Numbers" runat="server"></ajaxToolkit:FilteredTextBoxExtender>
                        </div>
                        <asp:Button ID="btnBuscarAvalado" CssClass="btn btn-default btn-sm" Text="Buscar" runat="server" OnClick="btnBuscarAvalado_Click" />
                    </div>
                    <asp:UpdatePanel ID="upAvalados" runat="server">
                        <ContentTemplate>
                            <div class="form-group">
                                <div class="col-md-8">
                                    <asp:Label ID="lblDatosAvalado" Text="" runat="server" />
                                </div>
                            </div>
                        </ContentTemplate>
                        <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="btnBuscarAvalado" EventName="Click" />
                        </Triggers>
                    </asp:UpdatePanel>
                </div>
            </div>
        </div>
        <div class="col-lg-6">
            <div class="box box-success">
                <div class="box-header with-border">
                    <h3 class="box-title">Datos del Prestamo</h3>
                </div>
                <div class="box-body">
                    <div class="form-group">
                        <label class="control-label col-md-2">Fecha</label>
                        <div class="col-md-10">
                            <asp:TextBox CssClass="form-control input-sm" ID="tbxFecha" runat="server" />
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="tbxFecha"
                                ErrorMessage=" Campo Necesario" ForeColor="Red"></asp:RequiredFieldValidator>
                            <ajaxToolkit:CalendarExtender ID="CalendarExtender1"
                                runat="server" Enabled="True" TargetControlID="tbxFecha"
                                Format="dd/MM/yyyy" TodaysDateFormat="dd/MM/yyyy"></ajaxToolkit:CalendarExtender>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2">Monto</label>
                        <div class="col-md-10">
                            <asp:TextBox CssClass="form-control input-sm" ID="tbxMonto" runat="server" />
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="tbxMonto"
                                ErrorMessage=" Campo Necesario" ForeColor="Red"></asp:RequiredFieldValidator>
                            <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender2" TargetControlID="tbxMonto"
                                FilterType="Numbers, Custom" ValidChars="." runat="server"></ajaxToolkit:FilteredTextBoxExtender>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2">Cuotas</label>
                        <div class="col-md-10">
                            <asp:TextBox CssClass="form-control input-sm" ID="tbxNroCuotas" runat="server" />
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator" runat="server" ControlToValidate="tbxNroCuotas"
                                ErrorMessage=" Campo Necesario" ForeColor="Red"></asp:RequiredFieldValidator>
                            <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender4" TargetControlID="tbxNroCuotas"
                                FilterType="Numbers" runat="server"></ajaxToolkit:FilteredTextBoxExtender>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2">Interes</label>
                        <div class="col-md-10">
                            <asp:TextBox CssClass="form-control input-sm" ID="tbxInteres" runat="server" />
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="tbxInteres"
                                ErrorMessage=" Campo Necesario" ForeColor="Red"></asp:RequiredFieldValidator>
                            <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender3" TargetControlID="tbxInteres"
                                FilterType="Numbers, Custom" ValidChars="." runat="server"></ajaxToolkit:FilteredTextBoxExtender>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2">Intervalo</label>
                        <div class="col-md-10">
                            <asp:DropDownList CssClass="form-control input-sm" ID="ddlIntervalo" runat="server">
                                <asp:ListItem Text="Quincenal" />
                                <asp:ListItem Text="Mensual" />
                                <asp:ListItem Text="Trimestral" />
                            </asp:DropDownList>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <asp:Button ID="btnGenerar" class="btn btn-default btn-sm" Text="Cuotas" runat="server" OnClick="btnGenerar_Click" />
                        </div>
                    </div>
                    <br />
                    <div class="form-group">
                        <div class="col-sm-offset-8">
                            <strong>Total: S/.
                                <asp:Label ID="lblTotalPrestamo" Text="" runat="server" /></strong>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="box box-success">
        <div class="box-header with-border">
            <h3 class="box-title">Cuotas de Pago</h3>
            <div class="box-tools pull-right">
                <button title="Collapse" data-toggle="tooltip" data-widget="collapse" class="btn btn-box-tool"><i class="fa fa-minus"></i></button>
            </div>
        </div>
        <div class="box-body">
            <asp:UpdatePanel ID="upCuotas" runat="server">
                <ContentTemplate>
                    <%--Start ListView--%>
                    <asp:ListView ID="lvCuotas" runat="server"
                        ItemType="Triunfadores.BusinessEntities.CuotaPago">
                        <EmptyDataTemplate>
                        </EmptyDataTemplate>
                        <LayoutTemplate>
                            <table class="table table-hover table-condensed">
                                <thead>
                                    <tr>
                                        <th>Fecha</th>
                                        <th>Monto</th>
                                        <th>Interes</th>
                                        <th>Total</th>
                                        <th>Estado</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr id="itemPlaceholder" runat="server" />
                                </tbody>
                            </table>
                        </LayoutTemplate>
                        <ItemTemplate>
                            <tr>
                                <td>
                                    <asp:Label ID="lblFechaPago" Text="<%# Bind('FechaPago','{0:d}') %>" runat="server" />
                                </td>
                                <td>
                                    <asp:Label ID="lblMonto" Text="<%# Bind('Monto') %>" runat="server" />
                                </td>
                                <td>
                                    <asp:Label ID="lblInteres" Text="<%# Bind('Interes') %>" runat="server" />
                                </td>
                                <td>
                                    <asp:Label ID="lblTotal" Text="<%# Bind('Total') %>" runat="server" />
                                </td>
                                <td>
                                    <asp:Label ID="lblEstado" Text="<%# Bind('Estado') %>" runat="server" />
                                </td>
                            </tr>
                        </ItemTemplate>
                    </asp:ListView>
                    <%--End ListView--%>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="btnGenerar" EventName="Click" />
                </Triggers>
            </asp:UpdatePanel>
        </div>
    </div>
    <div class="box-footer">
        <div class="pull-right">
            <a href="/Default.aspx" class="btn btn-default" type="button">Cancelar</a>
            <asp:Button class="btn btn-primary" ID="btnGuardar" Text="Guardar" runat="server" OnClick="btnGuardar_Click" />
        </div>
    </div>
    

    <script>
        $('#MainContent_btnGenerar').click(function () {
            //para cargar contenido
            var monto = $("#MainContent_tbxMonto").val();
            var interes = $("#MainContent_tbxInteres").val();
            var ganancia = parseFloat(monto * (interes / 100));
            var total = parseFloat(+monto + ganancia);
            //$("#MainContent_lblTotalPrestamo").text(total);

            document.getElementById("#[id*='lblTotalPrestamo']").html(total);

            //$("[id*='lblTotalPrestamo']").html(total);

            //$("[id*='lblTotalPrestamo']").change(function () {

            //    var tr = $(this).parent().parent();
            //    var precio = $("td:eq(1)", tr).html();

            //    $("td:eq(3) span", tr).html($(this).val() * precio);

            //});
        });
        
    </script>

</asp:Content>
